package com.example.superyi.mainBar.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.databean.Post;
import com.example.superyi.myteam.R;

import java.util.List;

public class HomePageAdapter  extends RecyclerView.Adapter {
    private final int N_Type = 0;//头部填充布局类型
    private final int F_Type = 1;//划分类型布局类型
    private final int A_Type = 2;//正常贴子布局类型

    private Boolean isFootView = true;//是否有footView
    private int Max_num = 16;
    private List<Post> Rc_homeItems;//存储首页中的items对象们

    private Context context;
    private List<Post> data;

    private OnItemClickListener mListener;

    public HomePageAdapter(Context context, List<Post> data){
        this.context = context;
        this.data = data;

    }
    public HomePageAdapter(Context context,OnItemClickListener listener){
        this.context = context;
        this.mListener = listener;
    }



    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.homepage_ord_item,parent,false);
        View headview = LayoutInflater.from(parent.getContext()).inflate(R.layout.homepage_head,parent,false);
        View footview = LayoutInflater.from(parent.getContext()).inflate(R.layout.homepage_foot_item,parent,false);
        View first_home_kinds = LayoutInflater.from(parent.getContext()).inflate(R.layout.homepage_kinds,parent,false);

        if(viewType == N_Type){
            //如果是第0个那么是head
            return new RecyclerViewHolder(headview,N_Type);
        }else  if(viewType == F_Type){
            //如果是第1个那么是种类分布布局
            return new RecyclerViewHolder(first_home_kinds,F_Type);
        }else{
            //其他是正常的
            return new RecyclerViewHolder(view,A_Type);
        }

    }


    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
//        if(isFootView && (getItemViewType(position))== F_Type){
//            final RecyclerViewHolder recyclerViewHolder = (RecyclerViewHolder) holder;
//        }



        Log.v("test","----------------运行到此处adpterposition"+position);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Log.v("test","----------------点击到此处的view的position"+position);
                mListener.onClick(position);

            }
        });



    }

    @Override
    public int getItemCount() {

        return Max_num;
    }

    //重写获取元素类型方法，对不通过类型划分标记
    @Override
    public int getItemViewType(int position) {
        if(position==0) {
            return  0;
        } else if(position==1){
            return 1;
        }else{
            return 2;
        }

    }

    //内部类
    //对主页的元素进行抓取操作的类,获得的视图中的属性可在onBindViewHolder中操作
    class RecyclerViewHolder extends RecyclerView.ViewHolder{
        //TextView textView;
        public RecyclerViewHolder(View item,int view_Type){
            super(item);

            //textView = item.findViewById();
        }

    }
    public interface OnItemClickListener{
        void onClick(int pos);

    }

}

